package com.xja.shoppingmall.controller;

import com.alibaba.fastjson.JSON;
import com.xja.shoppingmall.annotation.IgnoreResponseAdvice;
import com.xja.shoppingmall.service.JWTService;
import com.xja.shoppingmall.vo.JwtToken;
import com.xja.shoppingmall.vo.UsernameAndPassword;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CHENCHEN
 * @title
 * @createTime 2021-12-1217:08
 */
@Slf4j
@RestController
public class AuthorityController {

    @Autowired
    private JWTService jwtService;

    @IgnoreResponseAdvice
    @PostMapping("login")
    public JwtToken token(@RequestBody UsernameAndPassword usernameAndPassword) throws Exception {
        log.info("get token with param : [{}]", JSON.toJSONString(usernameAndPassword));

        return new JwtToken(jwtService.generatorToken(usernameAndPassword.getUsername(), usernameAndPassword.getPassword()));
    }
}
